<?php
/*
 * 后台禁用权限模块管理
 */
class Adminpower extends CI_Controller
{
	function __construct(){
		parent::__construct();
		$admin_id = $this->session->userdata('admin_id');
        if ( empty($admin_id ) ) {
			$this->load->helper('url');
        	redirect('login/index','refresh');
        }
        power($admin_id);
    }
    /*
     * 禁用权限模块列表
     */
	public function index($user = "")
	{
		$where = array();
		if(!empty($user)){
			$where = array('action_name'=>$user);
		}
        $query = $this->db->query("select distinct action_name from hl_admin_power");
       	$rowAct = $query->result();
		$data['rowAct'] = $rowAct;
		$total_rows = $this->db->where($where)->from('admin_power')->count_all_results();
		$per_page = 10;
		$this->load->library('page',array('total'=>$total_rows,'perpage'=>$per_page));
		$data['page'] = $this->page->show(1);
		$this->load->model('admin_model','mAdmin',TRUE);
        $data['results'] = $this->mAdmin->get_admin_power_list($per_page,$this->page->offset(),$where);
        $this->load->view('adminpower/index', $data);
	}
	/*
	 * 禁用权限模块添加
	 */
	public function add()
	{
		if(!is_post()){
			$where = array();
			$query = $this->db->where($where)->get('admin_node');
			$node = $query->result();
			foreach($node as $v){
				$action_name = $v->action_name;
				break;
			}
			$data['action_name'] = $action_name;
			$data['node'] = $node;
			$this->load->view('adminpower/add', $data);
		}else{
			$name = $_POST['action_name'];
			$power = $_POST['power'];
			$msg = array();
			$msg['action_name'] = $name;
			if ( count($power)>0 ){
				foreach ($power as $v){
					$msg['method_name'] = $v;
					$this->db->insert('admin_power', $msg);
					unset($msg['method_name']);
				}
			}
			display('添加成功',site_url("adminpower/add"));
		}
	}
	/*
	 * 获取方法
	 */
	public function getfuns($action_name)
	{
		$action_name = strtolower($action_name);
		include_once APPPATH.'/controllers/'.$action_name.".php";
		$methods = get_class_methods($action_name);
		$power = array();
		foreach ( $methods as $k=>$v ){
			if ( $v!='_initialize' && $v!='Controller' && $v!='__construct' && $v!=ucfirst($action_name) && $v!='_ci_initialize' && $v!='_ci_scaffolding' && $v!='CI_Base' && $v!='get_instance'){
				$power[] = $v;
			}
		}
		$data['power'] = $power;
		$this->load->view('adminpower/getfuns', $data);
	}
	/*
	 * 禁用权限模块删除
	 */
	public function delete($id)
	{
		$this->db->where('id', $id);
		$this->db->delete('admin_power');
		display('删除成功',site_url("adminpower/index"));
	}
}
?>